import request from '@/config/axios'

export interface EvalQuestionCategoryVO {
  id?: number
  categoryName: string
  categoryCode: string
  parentId: number
  categoryLevel: number
  categorySort: number
  categoryStatus: number
  categoryDescription?: string
  createTime?: Date
}

export interface EvalQuestionBankVO {
  id?: number
  categoryId: number
  questionType: string
  questionContent: string
  questionOptions?: string
  correctAnswer: string
  questionScore: number
  difficultyLevel: number
  questionStatus: number
  questionComments?: string
  createTime?: Date
}

export interface EvalQuestionCategoryPageReqVO extends PageParam {
  categoryName?: string
  categoryCode?: string
  parentId?: number
  categoryLevel?: number
  categoryStatus?: number
  createTime?: Date[]
}

export interface EvalQuestionBankPageReqVO extends PageParam {
  categoryId?: number
  questionType?: string
  difficultyLevel?: number
  questionStatus?: number
  questionContent?: string
  createTime?: Date[]
}

// 题库分类相关API
export const getQuestionCategoryPage = (params: EvalQuestionCategoryPageReqVO) => {
  return request.get({ url: '/eval/question-category/page', params })
}

export const getQuestionCategory = (id: number) => {
  return request.get({ url: '/eval/question-category/get?id=' + id })
}

export const createQuestionCategory = (data: EvalQuestionCategoryVO) => {
  return request.post({ url: '/eval/question-category/create', data })
}

export const updateQuestionCategory = (data: EvalQuestionCategoryVO) => {
  return request.put({ url: '/eval/question-category/update', data })
}

export const deleteQuestionCategory = (id: number) => {
  return request.delete({ url: '/eval/question-category/delete?id=' + id })
}

export const exportQuestionCategory = (params: EvalQuestionCategoryPageReqVO) => {
  return request.download({ url: '/eval/question-category/export-excel', params })
}

export const getQuestionCategoryTree = () => {
  return request.get({ url: '/eval/question-category/tree' })
}

export const getSimpleQuestionCategoryList = (): Promise<EvalQuestionCategoryVO[]> => {
  return request.get({ url: '/eval/question-category/simple-list' })
}

// 题库相关API
export const getQuestionBankPage = (params: EvalQuestionBankPageReqVO) => {
  return request.get({ url: '/eval/question-bank/page', params })
}

export const getQuestionBank = (id: number) => {
  return request.get({ url: '/eval/question-bank/get?id=' + id })
}

export const createQuestionBank = (data: EvalQuestionBankVO) => {
  return request.post({ url: '/eval/question-bank/create', data })
}

export const updateQuestionBank = (data: EvalQuestionBankVO) => {
  return request.put({ url: '/eval/question-bank/update', data })
}

export const deleteQuestionBank = (id: number) => {
  return request.delete({ url: '/eval/question-bank/delete?id=' + id })
}

export const exportQuestionBank = (params: EvalQuestionBankPageReqVO) => {
  return request.download({ url: '/eval/question-bank/export-excel', params })
}

export const getQuestionBankListByCategoryId = (categoryId: number) => {
  return request.get({ url: '/eval/question-bank/list-by-category?categoryId=' + categoryId })
}

export const getQuestionBankListByType = (questionType: string) => {
  return request.get({ url: '/eval/question-bank/list-by-type?questionType=' + questionType })
}

export const getQuestionBankListByDifficulty = (difficultyLevel: number) => {
  return request.get({ url: '/eval/question-bank/list-by-difficulty?difficultyLevel=' + difficultyLevel })
}

export const getQuestionBankListByStatus = (questionStatus: number) => {
  return request.get({ url: '/eval/question-bank/list-by-status?questionStatus=' + questionStatus })
}

// 批量导入题库
export const importQuestionBank = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  return request.post({ url: '/eval/question-bank/import', data: formData })
}

// 下载题库导入模板
export const importQuestionBankTemplate = () => {
  return request.download({ url: '/eval/question-bank/get-import-template' })
}

// 批量操作题库
export const batchUpdateQuestionBankStatus = (ids: number[], questionStatus: number) => {
  return request.put({ url: '/eval/question-bank/batch-update-status', data: { ids, questionStatus } })
}

// 随机抽取题目
export const randomSelectQuestions = (categoryId: number, questionCount: number, difficultyLevel?: number) => {
  return request.get({ 
    url: '/eval/question-bank/random-select', 
    params: { categoryId, questionCount, difficultyLevel } 
  })
}

// 获取题库统计信息
export const getQuestionBankStatistics = () => {
  return request.get({ url: '/eval/question-bank/statistics' })
}
